<?php

namespace app\model;

class DepartModel extends BaseModel
{
    protected  $table = 'depart';

    const STATUS = 1;

    const UN_STATUS = 2;

    /**
     * 获取所有部门名称信息
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function departInfo()
    {
        $where = [
            'status' => self::STATUS,
            'deleted' => self::DELETED,
        ];
        return self::where($where)->field(['id','depart_name'])->select();
    }




    /**
     * @param $page
     * @param $pageSize
     * @param array $condition
     * @param bool $is_count
     * @param string $order
     * @return false|int|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getDepartListPage($page,$pageSize,$condition=[],$is_count = false,$order=''){
        $condition['deleted'] = self::DELETED;
        $join=[
//            ['role role','role.role_id=admin.role_id','LEFT'],
//            ['bankinfo bank','bank.bank_id=admin.bank_id','LEFT'],
        ];
        $this->alias('admin')
            ->field('admin.*')
            ->join($join);
        if($condition){
            $this->where($condition);
        }
        if($order){
            $this->order($order);
        }
        if($is_count){
            return $this->count();
        }
        return $this->page($page,$pageSize)->select();
    }
}